//
//  HQVisitorView.m
//  wbOC
//
//  Created by sheji on 16/3/4.
//  Copyright (c) 2016年 sheji. All rights reserved.
//

#import "HQVisitorView.h"

@interface HQVisitorView ()
/**
   遮罩图像
 */
@property (nonatomic, strong) UIImageView *maskImageView;
/**
 *  图标
 */
@property (nonatomic, strong) UIImageView *iconView;
/**
 *  小房子
 */
@property (nonatomic, strong) UIImageView *homeIcon;
/**
 *  提示标签
 */
@property (nonatomic, strong) UILabel *messageLabel;

@end

@implementation HQVisitorView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//        self.backgroundColor = RandomColor;
        [self setupUI];
    }
    return self;
}
/**
 *  设置访客视图信息
 */
-(void)visitorInfoWihImageName:(NSString *)imageName message:(NSString *)message
{
    self.messageLabel.text = message;
    
    //根据图像名称是否为nil判断是否首页
    self.homeIcon.hidden = (imageName != nil);
    if (imageName != nil) {
        //设置图标图像
        self.iconView.image = [UIImage imageNamed:imageName];
        
        //将遮罩视图挪动到底部
        [self sendSubviewToBack:self.maskImageView];
    }else {
        //首页开始动画
        [self startAnimation];
    }
}
/**
 *  旋转图标动画
 */
-(void)startAnimation
{
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    
    //旋转角度
    anim.toValue = @(2 *M_PI);
    //重复次数
    anim.repeatCount = MAXFLOAT;
    //动画时长
    anim.duration = 20;
    //动画删除时是否删除
    anim.removedOnCompletion = NO;
    
    [self.iconView.layer addAnimation:anim forKey:nil];
}
#pragma mark - 设置界面
/**
 *  设置访客界面
 */
-(void)setupUI
{
    //1.背景颜色
    self.backgroundColor = [UIColor colorWithWhite:237.0/255.0 alpha:1.0];
    //2.添加控件
    [self addSubview:self.iconView];
    [self addSubview:self.maskImageView];
    [self addSubview:self.homeIcon];
    [self addSubview:self.messageLabel];
    [self addSubview:self.iconView];
    [self addSubview:self.registerButton];
    [self addSubview:self.loginButton];

    //3.自动布局
    //1.图标
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.mas_centerY).offset(-60);
    }];
    //2.小房子
    [self.homeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconView.mas_centerX);
        make.centerY.equalTo(self.iconView.mas_centerY);
        
    }];
    //3.消息
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconView.mas_centerX);
        make.top.equalTo(self.iconView.mas_bottom).offset(16);
        make.size.mas_equalTo(CGSizeMake(224, 35));
    }];
    //4.注册
    [self.registerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.messageLabel.mas_left);
        make.top.equalTo(self.messageLabel.mas_bottom).offset(16);
        make.size.mas_equalTo(CGSizeMake(100, 35));
    }];
    //5.登录
    [self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.messageLabel.mas_right);
        make.top.equalTo(self.messageLabel.mas_bottom).offset(16);
        make.size.mas_equalTo(CGSizeMake(100, 35));
    }];
    //6.遮罩
    [self.maskImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.top.equalTo(self.mas_top);
        make.bottom.equalTo(self.registerButton.mas_bottom);
    }];
}

#pragma mark - 懒加载控件
/**
 *  遮罩视图
 */
-(UIImageView *)maskImageView
{
    if (_maskImageView == nil) {
        _maskImageView =[UIImageView imageViewWithImageName:@"visitordiscover_feed_mask_smallicon"];
    }
    return _maskImageView;
}
/**
 *  图标
 */
-(UIImageView *)iconView
{
    if (_iconView == nil) {
        _iconView = [UIImageView imageViewWithImageName:@"visitordiscover_feed_image_smallicon"];
    }
    return _iconView;
}
/**
 *  小房子
 */
-(UIImageView *)homeIcon
{
    if (_homeIcon == nil) {
        _homeIcon = [UIImageView imageViewWithImageName:@"visitordiscover_feed_image_house"];
    }
    return _homeIcon;
}
/**
 *  消息
 */
-(UILabel *)messageLabel{
    if (_messageLabel == nil) {
        _messageLabel = [UILabel labelWithTitle:@"登录后，别人评论你的微博，发给你的消息，都会在这里收到通知" color:[UIColor darkGrayColor] fonSize:14];
    }
    return _messageLabel;
}
/**
 *  注册
 */
-(UIButton *)registerButton
{
    if (_registerButton == nil) {
        _registerButton = [UIButton buttonWithTitle:@"注册" titleColor:[UIColor orangeColor] backImageName:@"common_button_white_disable"];
    }
        return _registerButton;
}
/**
 *  登录
 */
-(UIButton *)loginButton
{
    if (_loginButton == nil) {
        _loginButton = [UIButton buttonWithTitle:@"登录" titleColor:[UIColor orangeColor] backImageName:@"common_button_white_disable"];
    }
    return _loginButton;
}
@end
